﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.bidmaterialinfo
{
    public partial class Modify : Web.Admin.BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int bmid = (Convert.ToInt32(Request.Params["id"]));
                    lcs.BLL.pmtypeinfo pmbll = new BLL.pmtypeinfo();
                    DataSet ds = pmbll.GetList("pmid>0");
                    ddlmtype.DataSource = ds;
                    ddlmtype.DataTextField = "pmtype";
                    ddlmtype.DataValueField = "pmid";
                    ddlmtype.DataBind();
                    ShowInfo(bmid);
                }
                Page.DataBind();
            }
        }

        private void ShowInfo(int bmid)
        {
            lcs.BLL.bidmaterialinfo bll = new lcs.BLL.bidmaterialinfo();
            lcs.Model.bidmaterialinfo model = bll.GetModel(bmid);
            this.lblbmid.Text = model.bmid.ToString();
            this.txtmbm.Text = model.mbm;
            this.txtmprice.Text = model.mprice.ToString();
            this.ddlmtype.SelectedValue = model.mtype.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtmbm.Text.Trim().Length == 0)
            {
                strErr += "编码不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtmprice.Text))
            {
                strErr += "价格格式错误！\\n";
            }
            
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int bmid = int.Parse(this.lblbmid.Text);
            string mbm = this.txtmbm.Text;
            decimal mprice = decimal.Parse(this.txtmprice.Text);
            int mtype =int.Parse( this.ddlmtype.SelectedValue.ToString());
            lcs.Model.bidmaterialinfo model = new lcs.Model.bidmaterialinfo();
            model.bmid = bmid;
            model.mbm = mbm;
            model.mprice = mprice;
            model.mtype = mtype;

            lcs.BLL.bidmaterialinfo bll = new lcs.BLL.bidmaterialinfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
